//
//  EnergyListCell.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/26.
//

#import "EnergyListCell.h"

@interface EnergyListCell()
@property (nonatomic,strong) UIImageView * iconview;
@property (nonatomic,strong) UILabel * infoLabel;
@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) YYLabel * priceLabel;
@property (nonatomic,strong) UIButton * enterbtn;
@end

@implementation EnergyListCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    self.backgroundColor = RDRGB(0xFBF9F7);
    [self setCornerRadius:9 * FMScaleX borderWidth:1 borderColor:RDRGB(0xDECFB9)];
    
    [self addSubview:self.iconview];
    [_iconview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(134 * FMScaleX, 134 * FMScaleX));
        make.top.equalTo(@0);
        make.centerX.equalTo(@0);
    }];
    [self addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@0);
        make.size.mas_offset(CGSizeMake(80 * FMScaleX, 20 * FMScaleX));
    }];
    [self addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.iconview.mas_bottom).offset(2 * FMScaleX);
    }];
    [self addSubview:self.priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(4 * FMScaleX);
    }];
    [self addSubview:self.enterbtn];
    [_enterbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(102 * FMScaleX, 30 * FMScaleX));
        make.top.equalTo(self.priceLabel.mas_bottom).offset(12 * FMScaleX);
        make.centerX.equalTo(@0);
    }];
}

-(void)setInfoModel:(EnergyShopListModel *)infoModel{
    
    [self.iconview sd_setImageWithURL:[NSURL URLWithString:infoModel.imageUrl]];
    self.nameLabel.text = infoModel.name;
    
    if (infoModel.price.length > 0) {
        NSMutableAttributedString * attstr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@" %@",infoModel.price]];

        NSMutableAttributedString * obj = [NSMutableAttributedString yy_attachmentStringWithContent:({
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 3 * FMScaleX, 26 * FMScaleX, 26 * FMScaleX)];
            imageView.image = [UIImage imageNamed:@"Energy_price_icon"];
            imageView;
              }) contentMode:UIViewContentModeRight attachmentSize:CGSizeMake(26 * FMScaleX, 26 * FMScaleX) alignToFont:Regular(16) alignment:YYTextVerticalAlignmentCenter];
        [attstr insertAttributedString:obj atIndex:0];
        self.priceLabel.attributedText = attstr;
        self.priceLabel.font = Bold(20);
        self.priceLabel.textColor = RDRGB(0xAD7D62);
        self.priceLabel.textAlignment = NSTextAlignmentCenter;
    }
}

-(UIImageView *)iconview{
    
    if (!_iconview) {
        _iconview = [[UIImageView alloc]init];
        _iconview.image = [UIImage imageNamed:@"Home_jiezhi_icon"];
    }
    return _iconview;
}
-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.backgroundColor = RDRGB(0xBF9360);
        _infoLabel.font = Regular(12);
        _infoLabel.textColor = UIColor.whiteColor;
        _infoLabel.text = @"每周四 10点";
        _infoLabel.textAlignment = NSTextAlignmentCenter;
        _infoLabel.hidden = YES;
    }
    return _infoLabel;
}
-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Regular(13);
        _nameLabel.textColor = RDRGB(0xAD7D62);
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}
-(YYLabel *)priceLabel{
    
    if (!_priceLabel) {
        _priceLabel = [[YYLabel alloc]init];
        _priceLabel.font = Bold(20);
        _priceLabel.textColor = RDRGB(0xAD7D62);
        _priceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLabel;
}
-(UIButton *)enterbtn{
    
    if (!_enterbtn) {
        _enterbtn = [[UIButton alloc]init];
        [_enterbtn setBackgroundImage:[UIImage imageNamed:@"Home_join_icon_no"] forState:UIControlStateNormal];
        [_enterbtn setTitle:@"立即参与" forState:UIControlStateNormal];
        [_enterbtn setTitleColor:RDRGB(0xAD7D62) forState:UIControlStateNormal];
        _enterbtn.userInteractionEnabled = NO;
    }
    return _enterbtn;
}
@end
